/***     
 * SP_THREE: 4, // 三张牌型
 */

var CardGroupType = require('./CardGroupType');
var FindSameCardValueTool = require('../FindTool/FindSameCardValueTool');
var _ = require('../Underscore');
var CardType = require('../CardType');
var CardTool = require('../CardTool');
var FindShunZiTool = require('../FindTool/FindShunZiTool');
var FindPairsTool = require('../FindTool/FindPairsTool');


var GroupFiveThree = module.exports = {};


GroupFiveThree.getName = function() {
    return '三张牌型';
};

GroupFiveThree.getType = function() {
    return CardGroupType.SP_THREE;
};

GroupFiveThree.getMoreResult = function(_cardInfoList) {
    var resultInfo = FindSameCardValueTool.getResult(_cardInfoList, 3);

    if (resultInfo.isFind) {
        var result = {
            isFind: true,
            findGroupMore: []
        }
        var size = _.size(resultInfo.findGroup);
        for (var i = 0; i < size; ++i) {
            //三张牌
            var findGroup = resultInfo.findGroup[i];
            var sanCards = _.difference(_cardInfoList, findGroup);

            //牌除掉对子
            var removePairs = FindPairsTool.getResult(sanCards, 1);
            if (removePairs.isFind) {
                //找出至少一对备用
                sanCards = _.difference(sanCards, removePairs.findGroup[0]);
            }
            // var sanCards = removePairs.otherGroup;
            sanCards = _.sortBy(sanCards, function(_cardInfo) {
                return _cardInfo.value
            });
            var sanCardSize = _.size(sanCards);
            findGroup.push(sanCards[sanCardSize - 1]);
            findGroup.push(sanCards[sanCardSize - 2]);
            var otherGroup = _.difference(_cardInfoList, findGroup);

            var info = {
                findGroup: findGroup,
                otherGroup: otherGroup
            }
            result.findGroupMore.push(info);
        }
        CardTool.LogResult(result, this.getName());
        return result;
    }
    CardTool.LogResult(resultInfo, this.getName());
    return resultInfo;
};